<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>flushbonading</title>

    <script crossorigin  type="module" th:src="@{{domain}js/div_import_0.0.0-dataease.js(domain=${vo.domain})}"></script>

</head>
<style>
    #dataease-container {
        display: inline-flex;
        width: 1000px;
        height: 800px;
        overflow: auto;
    }
</style>
<body>

<div id="dataease-container">
</div>
<div id="switch">切换</div>
</body>
<script th:inline="javascript" type="module">
    window.onload = () => {
        var xhr = new XMLHttpRequest();
        var account = [[${vo.account}]]
        var url = `/token/${account}`
        var resourceId = [[${vo.dashboardId}]]
        var opt = "create" //固定写法
        var domain = [[${vo.domain}]]
        let dataease = null
        let token = ''
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && xhr.status == 200) {
                token = xhr.response
                dataease = new DataEaseBi('DashboardEditor', {
                    baseUrl: domain,
                    token: token,
                    resourceId: resourceId,
                    opt: opt
                })
                dataease.initialize({container: '#dataease-container'})
            }
        }
        xhr.open('get', url, true);
        xhr.send();

        document.querySelector('#switch').addEventListener('click', () => {
            console.log('dataease', dataease)
            dataease.destroy()

            setTimeout(() => {
                dataease = new DataEaseBi('DashboardEditor', {
                    baseUrl: domain,
                    token: token,
                    resourceId: resourceId,
                    opt: opt
                })
                dataease.initialize({container: '#dataease-container'})
            }, 5000)
        })
    }



</script>

</html>